using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Collections;

using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Net.Sockets;

namespace Mud.EmlenMudMain
{
#if NO_SILVERLIGHT
    [Serializable]
#endif
    public class NoteData : INoteData
    {
        public NoteData() { }
        private string sender;	/* Note's sender */

        public string Sender
        {
            get { return sender; }
            set { sender = value; }
        }
        private string date;		/* Date it was sent */

        public string Date
        {
            get { return date; }
            set { date = value; }
        }
        private string to_list;	/* List of people it is to */

        public string To_list
        {
            get { return to_list; }
            set { to_list = value; }
        }
        private string subject;	/* Subject of the note */

        public string Subject
        {
            get { return subject; }
            set { subject = value; }
        }
        private string text;		/* The actual note text */

        public string Text
        {
            get { return text; }
            set { text = value; }
        }
        private int lines;		/* Lines of text in the note */

        public int Lines
        {
            get { return lines; }
            set { lines = value; }
        }
        private DateTime date_stamp;	/* Date stamp for unread notes */

        public DateTime Date_stamp
        {
            get { return date_stamp; }
            set { date_stamp = value; }
        }
        private int board_num;	/* Game Board number this note is located on */

        public int Board_num
        {
            get { return board_num; }
            set { board_num = value; }
        }

        public static bool Load(int inVersion)
        {
            if (NoteData.SerializeIn(inVersion) == false)
            {
                NoteData.SerializeOut(inVersion);
            }
            return true;
        }

        public static bool Save(int outVersion)
        {
            return NoteData.SerializeOut(outVersion);
        }

        public static bool SerializeIn(int inVersion)
        {
#if NO_SILVERLIGHT
            string szFName = EmlenMud.HostPathnameToMudDirectory + "\\" + MiscConstants.DataFileDirectory + "\\" + "Note." + typeof(NoteData).Name.ToString() + inVersion.ToString();
            Object o = SerializationHelper.SerializeObjectIn(szFName);
            if (o == null) return false;
            if (o is List<NoteData>)
            {
                List<NoteData> rgNotes = (List<NoteData>)o;
                foreach (NoteData note in rgNotes)
                {
                    //note.AssignEmlenMud();
                }
                EmlenMud.WorldTemplates.AllNotes = rgNotes;
                return true;
            }
            return false;
#else
            return true;
#endif
        }

        public static bool SerializeOut(int outVersion)
        {
#if NO_SILVERLIGHT
            string szFName = EmlenMud.HostPathnameToMudDirectory + "\\" + MiscConstants.DataFileDirectory + "\\" + "Note." + typeof(NoteData).Name.ToString() + outVersion.ToString();
            return SerializationHelper.SerializeObjectOut(EmlenMud.WorldTemplates.AllNotes, szFName, true);
#else
            return true;
#endif
        }

    }
}
